
// import * as mUtils from '@/utils/mUtils'
// import {getStore,removeStore} from '@/utils/mUtils'
function getStore(name) {
	return localStorage.getItem(name)
}

const user = {
	state: {
		id: getStore("USERID") || "",
		name: getStore("USERNAME") || "",
		avatar: getStore("AVATAR") || "",
		token: getStore("DEVELOPID") || "",
		myPostCount: getStore("POSTCOUNT") || '',
		myEvaluateCount: getStore("EVALUATECOUNT") || "",
	},
	getters: {
		token: state => state.token,
		roles: state => state.roles,
		avatar: state => state.avatar,
		name: state => state.name,
		admin: state => state.admin,
	},
	mutations: {
		SET_TOKEN: (state, token) => {
			localStorage.setItem("DEVELOPID", token);
			state.token = token
		},
		SET_USERINFO: (state, data) => {
			// console.log(data)
			localStorage.setItem("USERID", data.id);
			localStorage.setItem("USERNAME", data.accountName);
			localStorage.setItem("AVATAR", data.logo);
			state.id = data.id
			state.name = data.accountName
			state.avatar = data.logo
		},
		SET_MOREINFO: (state, data) => {
			// console.log(data)
			localStorage.setItem("POSTCOUNT", data.myPostCount);
			localStorage.setItem("EVALUATECOUNT", data.myEvaluateCount);
			state.myPostCount = data.myPostCount
			state.myEvaluateCount = data.myEvaluateCount
		},
		// SET_ROLES: (state, roles) => {
		// 	state.roles = roles
		// },
		// SET_NAME: (state, name) => {
		// 	console.log(name)
		// 	state.name = name
		// },
		// SET_AVATAR: (state, avatar) => {
		// 	state.avatar = avatar
		// },
		// SET_ADMIN: (state, admin) => {
		// 	state.admin = admin
		// }
	},
	actions: {
		// getIsAdmin({ commit }, payload) {
		// 	return new Promise((resolve, reject) => {
		// 		commit('SET_ADMIN', payload)
		// 		resolve();
		// 	})
		// },
		// getAvatar({ commit }, payload) {
		// 	commit('SET_AVATAR', payload)
		// }
	}
}

export default user;
